﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using IcecreamView;
using EasyGameTemplate;

/// <summary>
/// 游戏主体逻辑
/// </summary>
public class M_GameManager : SingletonTemplate<M_GameManager> {

    //----------------------------可配置参数
    //UI父节点
    public Transform canvasTransform;
    //UI配置表
    public GameViewConfig viewConfig;
    //对象池配置表
    public GamePoolConfig poolConfig;
    //图片配置表
    public D_mineSpriteConfig mineSpriteConfig;

    //----------------------------功能组件
    //UI管理器
    public GameViewManager viewManager;
    //对象管理器
    public GamePoolManager poolManager;
    [HideInInspector]
    //网格生成
    public M_GridManager gridManager;

    //----------------------------数据层
    public D_mineCommonData mineCommonData;

    private void Start()
    {
        DontDestroyOnLoad(this);
        InitGame();
    }

    /// <summary>
    /// 游戏初始化
    /// </summary>
    public void InitGame() {
        Debug.Log("游戏初始化");
        viewManager = GameViewManager.InstantiateViewManager(viewConfig, canvasTransform);
        poolManager = new GamePoolManager(poolConfig);
        mineCommonData = new D_mineCommonData();
        gridManager = new M_GridManager().InitGridManager();
    }
    /// <summary>
    /// 重置游戏
    /// </summary>
    public void GameReset() {
        gridManager.GridClear();
    }

    /// <summary>
    /// 开始游戏
    /// </summary>
    public void GameStart() {
        GameReset();
        mineCommonData.isLockInput = false;
        gridManager.GridCreator(8, 12);
        gridManager.MineCreator(10);
        //TestGame();
        viewManager.OpenViewAndCloseOther("GamePanel");
    }

    /// <summary>
    /// 结束游戏
    /// </summary>
    public void GameOver() {
        mineCommonData.isLockInput = true;
        gridManager.GridClear();
    }

    public void TestGame() {
        mineCommonData.mineEntityList.ForEach(e => {
            e.OnShortClick();
        });
    }

    /// <summary>
    /// 退出游戏
    /// </summary>
    public void ExitGame() {

    }
}
